package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Gallery;

@Repository
public interface GalleryRepository extends JpaRepository<Gallery,Integer> {
	
	// List the galleries that belongs to a customer
	@Query("select g from Gallery g where g.customer.id = ?1")
	Collection<Gallery> findGalleriesByCustomerId(int customerId);

	// Select the most expensive gallery
	@Query("select p.gallery from Painting p group by p.gallery having sum(p.appraisal) >= all(select sum(pAux.appraisal) from Painting pAux group by pAux.gallery)")
	Collection<Gallery> findMostExpensiveGallery();
	
}
